package shujujiegou;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import org.junit.Test;


public class InputFile {
	//"C:/Users/Administrator/Desktop/test.txt"
	private String filePath = "C:/Users/Administrator/Desktop/1.exe";
	
	//һ���ֱ��ò��������������ķ�ʽ��ȡ�ļ�test.txt���������ַ�ʽ��Ч�ʡ�
	@Test
	public void test1(){
		File file = new File(filePath);
		FileInputStream fis = null;
		try {
			fis = new FileInputStream(file);
			byte[] bs = new byte[1024];
			int len = 0;
			while((len = fis.read(bs))!=-1){
//				System.out.print(new String(bs, 0, len, "UTF-8"));
			}
			System.out.println();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		
	}
	@Test
	public void test2(){
		File file = new File(filePath);
		FileInputStream fis = null;
		try {
			fis = new FileInputStream(file);
			BufferedInputStream bis = new BufferedInputStream(fis);
			byte[] bs = new byte[1024];
			int len = 0;
			while((len = bis.read(bs))!=-1){
//				System.out.print(new String(bs, 0, len, "UTF-8"));
			}
			System.out.println();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
	
	@Test
	public void test3(){
		File file = new File(filePath);
		FileInputStream fis = null;
		try {
			fis = new FileInputStream(file);
			byte[] bs = new byte[fis.available()];
			int len = 0;
			fis.read(bs);
//			while((len = fis.read(bs))!=-1){
////				System.out.print(new String(bs, 0, len, "UTF-8"));
//			}
			System.out.println();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		
	}
	
	
	@Test
	public void test(){
		long start = System.currentTimeMillis();
		test1();
		System.out.println(System.currentTimeMillis() - start);
		
		start = System.currentTimeMillis();
		test2();
		System.out.println(System.currentTimeMillis() - start);
		
		start = System.currentTimeMillis();
		test3();
		System.out.println(System.currentTimeMillis() - start);
		
	}
	
	
	
}
